package blue.mqtt4j.internal.client.impl;

import blue.mqtt4j.client.MqttQoS;
import blue.mqtt4j.client.MqttTopic;

import java.util.Objects;

/**
 * @author Jin Zheng
 * @since 1.0 2020-11-26
 */
public class DefaultMqttTopic implements MqttTopic
{
	private final String topic;
	private final MqttQoS qos;

	public DefaultMqttTopic(String topic, MqttQoS qos)
	{
		this.topic = topic;
		this.qos = qos;
	}

	@Override
	public String topic()
	{
		return topic;
	}

	@Override
	public MqttQoS qos()
	{
		return qos;
	}

	@Override
	public String toString()
	{
		return String.format("%s{topic: %s, qos: %s}", this.getClass().getSimpleName(), topic, qos);
	}

	@Override
	public boolean equals(Object o)
	{
		if (this == o)
		{
			return true;
		}
		if (o == null || getClass() != o.getClass())
		{
			return false;
		}
		DefaultMqttTopic that = (DefaultMqttTopic) o;
		return topic.equals(that.topic);
	}

	@Override
	public int hashCode()
	{
		return Objects.hash(topic);
	}
}
